package com.edu.exam.entity.curriculum.questionbank;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 填空题实体类
 * 所属模块：B-02 题库管理模块
 * 对应数据库表：fill_question_base
 *
 * 根据B-02-03-05填空题管理子模块设计文档实现
 * 管理填空题的基础信息，包括题干内容、填空位置设置、标准答案配置等。
 * 支持智能填空位置识别和多答案匹配。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "fill_question_base")
@Comment("填空题基础信息表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class FillInQuestion {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 题目唯一标识符
     */
    @NotBlank(message = "题目ID不能为空")
    @Size(max = 50, message = "题目ID长度不能超过50个字符")
    @Column(name = "question_id", nullable = false, length = 50, unique = true)
    private String questionId;

    /**
     * 题目标题
     */
    @NotBlank(message = "题目标题不能为空")
    @Size(max = 200, message = "题目标题长度不能超过200个字符")
    @Column(name = "title", nullable = false, length = 200, unique = true)
    private String title;

    /**
     * 题目分类ID
     */
    @Column(name = "category_id")
    private Long categoryId;

    /**
     * 科目ID
     */
    @Column(name = "subject_id")
    private Long subjectId;

    /**
     * 题目类型（FILL_IN_BLANK-填空题，MULTI_FILL-多空填空）
     */
    @NotBlank(message = "题目类型不能为空")
    @Size(max = 30, message = "题目类型长度不能超过30个字符")
    @Column(name = "question_type", nullable = false, length = 30)
    private String questionType;

    /**
     * 难度等级（1-5分）
     */
    @NotNull(message = "难度等级不能为空")
    @Column(name = "difficulty_level", nullable = false)
    private Integer difficultyLevel;

    /**
     * 题目总分
     */
    @NotNull(message = "题目总分不能为空")
    @Column(name = "score", nullable = false, precision = 8, scale = 2)
    private BigDecimal score;

    /**
     * 题干内容（包含填空标记）
     */
    @NotBlank(message = "题干内容不能为空")
    @Column(name = "stem_text", nullable = false, columnDefinition = "TEXT")
    private String stemText;

    /**
     * 填空位置数量
     */
    @NotNull(message = "填空位置数量不能为空")
    @Column(name = "blank_count", nullable = false)
    private Integer blankCount;

    /**
     * 填空位置配置（JSON格式）
     */
    @Column(name = "blank_positions", columnDefinition = "TEXT")
    private String blankPositions;

    /**
     * 题目状态（DRAFT-草稿，PENDING-待审核，APPROVED-已通过，PUBLISHED-已发布，REJECTED-已拒绝，ARCHIVED-已归档）
     */
    @NotBlank(message = "题目状态不能为空")
    @Size(max = 20, message = "题目状态长度不能超过20个字符")
    @Column(name = "status", nullable = false, length = 20)
    private String status;

    /**
     * 题目版本
     */
    @NotNull(message = "题目版本不能为空")
    @Column(name = "version", nullable = false)
    private Integer version;

    /**
     * 答案解析
     */
    @Column(name = "answer_explanation", columnDefinition = "TEXT")
    private String answerExplanation;

    /**
     * 解析提示
     */
    @Column(name = "answer_hint", columnDefinition = "TEXT")
    private String answerHint;

    /**
     * 知识点
     */
    @Column(name = "knowledge_points", columnDefinition = "TEXT")
    private String knowledgePoints;

    /**
     * 题目标签（JSON格式）
     */
    @Column(name = "tags", columnDefinition = "TEXT")
    private String tags;

    /**
     * 适用年级
     */
    @Size(max = 50, message = "适用年级长度不能超过50个字符")
    @Column(name = "grade_level", length = 50)
    private String gradeLevel;

    /**
     * 题目来源（ORIGINAL-原创，IMPORT-导入，CONTRIBUTION-贡献）
     */
    @Size(max = 30, message = "题目来源长度不能超过30个字符")
    @Column(name = "question_source", length = 30)
    private String questionSource;

    /**
     * 预估答题时间（分钟）
     */
    @Column(name = "estimated_time_minutes")
    private Integer estimatedTimeMinutes;

    /**
     * 是否允许部分得分
     */
    @NotNull(message = "部分得分设置不能为空")
    @Column(name = "allow_partial_score", nullable = false)
    private Boolean allowPartialScore;

    /**
     * 每个空位的分数（平均分配）
     */
    @Column(name = "score_per_blank", precision = 6, scale = 2)
    private BigDecimal scorePerBlank;

    /**
     * 智能批阅模式（EXACT-精确匹配，FUZZY-模糊匹配，SEMANTIC-语义匹配，INTELLIGENT-智能匹配）
     */
    @Size(max = 30, message = "批阅模式长度不能超过30个字符")
    @Column(name = "grading_mode", length = 30)
    private String gradingMode;

    /**
     * 容错设置（JSON格式）
     */
    @Column(name = "tolerance_settings", columnDefinition = "TEXT")
    private String toleranceSettings;

    /**
     * 是否区分大小写
     */
    @NotNull(message = "大小写设置不能为空")
    @Column(name = "case_sensitive", nullable = false)
    private Boolean caseSensitive;

    /**
     * 是否启用同义词匹配
     */
    @NotNull(message = "同义词匹配设置不能为空")
    @Column(name = "synonym_enabled", nullable = false)
    private Boolean synonymEnabled;

    /**
     * 使用次数
     */
    @Column(name = "usage_count")
    private Integer usageCount;

    /**
     * 正确率
     */
    @Column(name = "accuracy_rate", precision = 5, scale = 4)
    private BigDecimal accuracyRate;

    /**
     * 平均答题时间
     */
    @Column(name = "average_time_seconds", precision = 8, scale = 2)
    private BigDecimal averageTimeSeconds;

    /**
     * 难度系数（基于实际答题数据）
     */
    @Column(name = "difficulty_index", precision = 5, scale = 4)
    private BigDecimal difficultyIndex;

    /**
     * 区分度（题目区分不同水平学生的能力）
     */
    @Column(name = "discrimination_index", precision = 5, scale = 4)
    private BigDecimal discriminationIndex;

    /**
     * 质量评分（1-5分）
     */
    @Column(name = "quality_score", precision = 3, scale = 2)
    private BigDecimal qualityScore;

    /**
     * 扩展数据（JSON格式）
     */
    @Column(name = "extended_data", columnDefinition = "TEXT")
    private String extendedData;

    /**
     * 软删除标识
     */
    @NotNull(message = "软删除标识不能为空")
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 创建人ID
     */
    @NotBlank(message = "创建人ID不能为空")
    @Size(max = 50, message = "创建人ID长度不能超过50个字符")
    @Column(name = "creator_id", nullable = false, length = 50)
    private String creatorId;

    /**
     * 创建人姓名
     */
    @Size(max = 50, message = "创建人姓名长度不能超过50个字符")
    @Column(name = "creator_name", length = 50)
    private String creatorName;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新人ID
     */
    @Size(max = 50, message = "更新人ID长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;

    /**
     * 更新时间
     */
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 审核人ID
     */
    @Size(max = 50, message = "审核人ID长度不能超过50个字符")
    @Column(name = "reviewer_id", length = 50)
    private String reviewerId;

    /**
     * 审核时间
     */
    @Column(name = "review_time")
    private LocalDateTime reviewTime;

    /**
     * 发布时间
     */
    @Column(name = "publish_time")
    private LocalDateTime publishTime;

}